package CI.aufgabe2.cip.mynodes;


import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;

import java.util.List;

public class MyDeclarationsNode extends MyAbstractNode{


	private static final long serialVersionUID = 1L;
	private final List<MyConstDeclarationNode> consts;
	private final List<MyTypeDeclarationNode> types;
	private final List<MyVarDeclarationNode> vars;
	private final List<MyProcedureDeclarationNode> procDeclarations;
	
	private int memorySize = 0;

	
	public MyDeclarationsNode (List<MyConstDeclarationNode> c, List<MyTypeDeclarationNode> t, List<MyVarDeclarationNode> v,
								List<MyProcedureDeclarationNode> pD){
		consts = c;
		types = t;
		vars = v;
		procDeclarations = pD;
	}
	
	
	@Override
	public void print() {
		trace("DeclarationsNode ");
		if (consts != null){
			for (int i = 0; i < consts.size(); i++) {
				consts.get(i).print();
			}
		}
		if (types != null){
			for (int i = 0; i < types.size(); i++) {
				types.get(i).print();
			}
		}
		if (vars != null){
			for (int i = 0; i < vars.size(); i++) {
				vars.get(i).print();
			}
		}
		if (procDeclarations != null){
			for (int i = 0; i < procDeclarations.size(); i++) {
				procDeclarations.get(i).print();
			}
		}
		unindent();
	}
	
	public int getSize() {
		return memorySize;
	}
	
	
	public AbstractDescr compile(SymbolTable sym) {
		
		
		for(MyAbstractNode typeNode : types){
			memorySize += typeNode.compile(sym).getSize();
		}
		
		for(MyVarDeclarationNode varNode : vars){
			memorySize += varNode.compile(sym).getSize()*varNode.getSize();
		}
		
		for(MyProcedureDeclarationNode procNode : procDeclarations){
			procNode.compile(sym);
		}
		return null;
	}
	public AbstractDescr compileConst(SymbolTable sym){
		for(MyConstDeclarationNode constNode : consts){
			memorySize += constNode.compile(sym).getSize();
		}
		return null;
	}
	
}
